import base64
import os
import sys
 
# Base64转图片
def base64_to_image(base64_str, output_path):
   image_data = base64.b64decode(base64_str)
   with open(output_path, 'wb') as image_file:
       image_file.write(image_data)
 
# 读取并打印文件的行数和内容
def read_and_print_file(file_path):
   line_count = 0
   with open(file_path, 'r') as file:
       for line in file:
           line_count += 1
           # 假设每行是一个Base64编码的字符串
           base64_str = line.strip()
           output_path = f"{line_count}.jpg"
           base64_to_image(base64_str, output_path)
           print(f"Line {line_count}: Image saved to {output_path}")
 
   print(f"Total lines: {line_count}")
 
if __name__ == "__main__":
   if len(sys.argv) != 2:
       print("Usage: python script.py <file_path>")
       sys.exit(1)
 
   file_path = sys.argv[1]
   read_and_print_file(file_path)
